package cn.kgc.sm.service.impl;

import cn.kgc.sm.entity.User;
import cn.kgc.sm.mapper.UserMapper;
import cn.kgc.sm.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/2/23
 * @Description:   @Transactional
 * @Transactional  位置 类上   整个类中的方法全是使用事务控制
 * @Transactional  位置 方法   只有当前方法有事务控制
 * @Transactional  注解参数
 *   isolation    事务的隔离级别  四种
 *   rollbackFor   设置回滚的异常类型    NullPointerException.class  []
 *   noRollbackFor  设置出现指定异常不回滚
 *   propagation    设置事务的传播机制    A->B
 *
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> selectAll() {

        List<User> users = userMapper.selectAll();

        return users;
    }

    @Override
    public List<User> selectPage(Integer currentPage, Integer limit) {

        PageHelper.startPage(currentPage, limit);
        List<User> users = userMapper.selectAll();
        PageInfo<User> userPageInfo = new PageInfo<>(users);

        return users;
    }

    @Override
    //@Transactional
    public Integer deleteById(Integer id) {

        Integer integer = userMapper.deleteById(id);

        if(id==5){
            throw new RuntimeException("出现异常");
        }

        return integer ;
    }


}
